﻿using System;
using System.Collections.Specialized;

public partial class ExampleWidget : WidgetBase
{
	/// <summary>
	/// Nazev widgetu (je shodny s nazvem adresare obsahujici widget)
	/// </summary>
	public override string Name
	{
		get { return "ExampleWidget"; }
	}

	/// <summary>
	/// Titulek zobrazovany v hlavicce widgetu
	/// </summary>
	public override string Title
	{
		get { return (string)GetLocalResourceObject("Title"); }
	}

	/// <summary>
	/// Nacteni widgetu
	/// </summary>
	public override void LoadWidget()
	{
		// Load settings
		StringDictionary settings = this.GetSettings();
		if (settings.ContainsKey("exampleSetting"))
		{
			this.tbSetting.Text = settings["exampleSetting"];
		}
		this.lblExample.Text = this.tbSetting.Text;
	}

	/// <summary>
	/// Vraci vychozi nastaveni widgetu
	/// </summary>	
	public override StringDictionary GetDefaultSettings()
	{
		StringDictionary settings = new StringDictionary();
		settings.Add("exampleSetting", String.Empty);
		return settings;
	}

	/// <summary>
	/// Priznak o tom, zda je widget editovatelny
	/// </summary>
	public override bool IsEditable
	{
		get { return true; }
	}

	/// <summary>
	/// Zobrazi editacni cast widgetu.
	/// </summary>
	public override void ShowEdit()
	{
		base.ShowEdit();
		this.DivEdit.Visible = true;
	}

	/// <summary>
	/// Skryje editacni cast widgetu.
	/// </summary>
	public override void HideEdit()
	{
		base.HideEdit();
		this.DivEdit.Visible = false;
	}

	/// <summary>
	/// Ulozi zvolene nastaveni.
	/// </summary>
	protected void SaveSettings(object sender, EventArgs e)
	{
		StringDictionary settings = this.GetSettings();
		if (!settings.ContainsKey("exampleSetting"))
		{
			settings = this.GetDefaultSettings();
		}
		settings["exampleSetting"] = this.tbSetting.Text;
		this.SaveSettings(settings);
		this.HideEdit();
	}
}




